package com.aree.caipiao.shsq.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.aree.caipiao.model.IdEntity;

@Entity
@Table(name="t_shuangseqiu")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class ShuangSeQiuResult extends IdEntity {
	private static final long serialVersionUID = -3120433985580040881L;
	public static final String SPLITER = ",";
	private String date; // 开奖日期
	private String serial; // 期号
	private int red1;
	private int red2;
	private int red3;
	private int red4;
	private int red5;
	private int red6;
	private int blue;
	private int sale; // 销售额
	private int top1Num; // 一等奖注数
	private int top2Num; // 二等奖注数
	
	public ShuangSeQiuResult() {}
	
	@Column(name="date", nullable=false, unique=true)
	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}
	
	@Column(name="serial", nullable=false, length=7, unique=true)
	public String getSerial() {
		return serial;
	}

	public void setSerial(String serial) {
		this.serial = serial;
	}
	
	@Column(name="sale", nullable=false)
	public int getSale() {
		return sale;
	}

	public void setSale(int sale) {
		this.sale = sale;
	}
	
	@Column(name="top1Num")
	public int getTop1Num() {
		return top1Num;
	}

	public void setTop1Num(int top1Num) {
		this.top1Num = top1Num;
	}
	
	@Column(name="top2Num")
	public int getTop2Num() {
		return top2Num;
	}

	public void setTop2Num(int top2Num) {
		this.top2Num = top2Num;
	}
	
	@Column(name="red1", nullable=false)
	public int getRed1() {
		return red1;
	}

	public void setRed1(int red1) {
		this.red1 = red1;
	}
	
	@Column(name="red2", nullable=false)
	public int getRed2() {
		return red2;
	}

	public void setRed2(int red2) {
		this.red2 = red2;
	}
	
	@Column(name="red3", nullable=false)
	public int getRed3() {
		return red3;
	}

	public void setRed3(int red3) {
		this.red3 = red3;
	}
	
	@Column(name="red4", nullable=false)
	public int getRed4() {
		return red4;
	}

	public void setRed4(int red4) {
		this.red4 = red4;
	}
	
	@Column(name="red5", nullable=false)
	public int getRed5() {
		return red5;
	}

	public void setRed5(int red5) {
		this.red5 = red5;
	}
	
	@Column(name="red6", nullable=false)
	public int getRed6() {
		return red6;
	}

	public void setRed6(int red6) {
		this.red6 = red6;
	}
	
	@Column(name="blue", nullable=false)
	public int getBlue() {
		return blue;
	}

	public void setBlue(int blue) {
		this.blue = blue;
	}
	
	@Transient
	public int getTotal() {
		return this.red1 + this.red2 + this.red3 + this.red4 + this.red5 + this.red5 + this.blue;
	}
	
	public static ShuangSeQiuResult build(String stringObject) {
		ShuangSeQiuResult result = new ShuangSeQiuResult();
		String[] array = stringObject.split(SPLITER, 12);
		if (array.length != 12) {
			throw new IllegalArgumentException("字符串必须含11个" + SPLITER);
		}
		result.setDate(array[0]);
		result.setSerial(array[1]);
		result.setRed1(Integer.parseInt(array[2]));
		result.setRed2(Integer.parseInt(array[3]));
		result.setRed3(Integer.parseInt(array[4]));
		result.setRed4(Integer.parseInt(array[5]));
		result.setRed5(Integer.parseInt(array[6]));
		result.setRed6(Integer.parseInt(array[7]));
		result.setBlue(Integer.parseInt(array[8]));
		result.setSale(StringUtils.isEmpty(array[9]) ? 0 : Integer.parseInt(array[9]));
		result.setTop1Num(StringUtils.isEmpty(array[10]) ? 0 : Integer.parseInt(array[10]));
		result.setTop2Num(StringUtils.isEmpty(array[11]) ? 0 : Integer.parseInt(array[11]));
		return result;
	}

	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append(this.date).append(",");
		buf.append(this.serial).append(",");
		buf.append(this.red1).append(",");
		buf.append(this.red2).append(",");
		buf.append(this.red3).append(",");
		buf.append(this.red4).append(",");
		buf.append(this.red5).append(",");
		buf.append(this.red6).append(",");
		buf.append(this.blue).append(",");
		buf.append(this.top1Num).append(",");
		buf.append(this.top2Num);
		return buf.toString();
	}

}
